home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / xmodem3.9 / part03 < prev    next >
Encoding:
Internet Message Format  |  1991-01-08  |  26.9 KB

  1. Subject:  v23i079:  Xmodem file transfer program, revision3.9, Part03/03
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 575aa8c4 3acd406b 3e11e97b e8f114c2
  5.  
  6. Submitted-by: Steve Grandi <grandi@noao.edu>
  7. Posting-number: Volume 23, Issue 79
  8. Archive-name: xmodem3.9/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  batch.c misc.c xmodem.1 xmodem.h
  17. # Wrapped by rsalz@litchi.bbn.com on Wed Dec  5 12:31:58 1990
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 3 (of 3)."'
  21. if test -f 'batch.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'batch.c'\"
  23. else
  24.   echo shar: Extracting \"'batch.c'\" \(4901 characters\)
  25.   sed "s/^X//" >'batch.c' <<'END_OF_FILE'
  26. X/*
  27. X *  Various routines for batch transfer
  28. X */
  29. X
  30. X#include "xmodem.h"
  31. X
  32. X/* make sure filename sent or received in YMODEM batch is canonical. */
  33. X
  34. X/* Incoming: Turn Unix '/' into CP/M ':' and translate to all lower case.
  35. X * Remove trailing dot.
  36. X */
  37. X
  38. Xunixify (name)
  39. Xchar *name;
  40. X    {
  41. X    char *ptr;
  42. X
  43. X    /* change '/' to ':' and convert to lower case */
  44. X    for (ptr=name; *ptr; ++ptr)
  45. X        {
  46. X        if (*ptr == '/')
  47. X            *ptr = ':';
  48. X        if (isupper (*ptr))
  49. X            *ptr |= 040;
  50. X        }
  51. X
  52. X    /* remove trailing dot if present */
  53. X    ptr--;
  54. X    if (*ptr == '.')
  55. X        *ptr = '\0';
  56. X    }
  57. X
  58. X/* make sure filename sent or received in YMODEM batch is canonical. */
  59. X
  60. X/* Outgoing: Turn ':' into '/' (for symmetry!) and turn into all lower case.
  61. X * Remove everything before last '/'.  Use "filename" to hold final name.
  62. X */
  63. X
  64. Xchar *
  65. Xcpmify (name)
  66. Xchar *name;
  67. X    {
  68. X    char *ptr, *slash;
  69. X    char *strcpy();
  70. X
  71. X    /* find last '/' and copy rest of name */
  72. X
  73. X    slash = name;
  74. X    for (ptr=name; *ptr; ++ptr)
  75. X        if (*ptr == '/')
  76. X            slash = ptr + 1;
  77. X    strcpy (filename, slash);
  78. X
  79. X    /* change ':' to '/' and covert to all lower case */
  80. X
  81. X    for (ptr=filename; *ptr; ++ptr)
  82. X        {
  83. X        if (*ptr == ':')
  84. X            *ptr = '/';
  85. X        if (isupper (*ptr))
  86. X            *ptr |= 040;
  87. X        }
  88. X    return (filename);
  89. X    }
  90. X
  91. X
  92. X/* convert a CP/M file name received in a MODEM7 batch transfer
  93. X * into a unix file name mapping '/' into ':', converting to all
  94. X * upper case and adding dot in proper place.  
  95. X * Use "filename" to hold name.
  96. X * Code stolen from D. Thompson's (IRTF) xmodem.c
  97. X */
  98. X
  99. Xchar *
  100. Xcpm_unix (string)
  101. Xunsigned char *string;
  102. X{
  103. X    register int i;
  104. X    unsigned char *iptr, temp;
  105. X    register char *optr;
  106. X
  107. X    if (*string == '\0')
  108. X        error("Null file name in MODEM7 batch receive", TRUE);
  109. X
  110. X    for (iptr=string; (temp = *iptr) ; ) {
  111. X        temp &= 0177;            /* strips bit 7 */
  112. X        if (isupper(temp))
  113. X            temp |= 040;        /* set bit 5 for lower case */
  114. X        if (temp == '/') 
  115. X            temp=':';        /* map / into : */
  116. X        *iptr++ = temp;
  117. X    }
  118. X
  119. X    /* put in main part of name */
  120. X    iptr=string;
  121. X    optr=filename;
  122. X    for (i=0; i<8; i++) {
  123. X        if (*iptr != ' ')
  124. X            *optr++ = *iptr++;
  125. X    }
  126. X
  127. X    /* add dot if necessary */
  128. X    if (string[8] != ' ' || string[9] != ' ' || string[10] != ' ')
  129. X        *optr++ = '.';
  130. X
  131. X    /* put in extension */
  132. X    iptr = &string[8];
  133. X    for (i=0; i<3; i++) {
  134. X        if (*iptr != ' ')
  135. X            *optr++ = *iptr++;
  136. X    }
  137. X
  138. X    *optr++ = '\000';
  139. X    return (filename);
  140. X}
  141. X
  142. X/* Send 11 character CP/M filename for MODEM7 batch transmission
  143. X * Returns -1 for a protocol error; 0 if successful
  144. X * NOTE: we tromp a little on the argument string!
  145. X * code stolen from D. Thompson's (IRTF) xmodem.c
  146. X */
  147. X
  148. Xsend_name(name)
  149. Xchar *name;
  150. X{
  151. X    register int cksum;
  152. X    register char *ptr;
  153. X
  154. X    xmdebug("send_name");
  155. X
  156. X    /* append cp/m EOF */
  157. X    name[NAMSIZ] = CTRLZ;
  158. X    name[NAMSIZ+1] = '\000';
  159. X
  160. X    /* create checksum */
  161. X    ptr = name;
  162. X    cksum = 0;
  163. X    while (*ptr)
  164. X        cksum += *ptr++;
  165. X    cksum &= 0x00FF;
  166. X
  167. X    /* send filename */
  168. X
  169. X    sendbyte(ACK);
  170. X    ptr = name;
  171. X    sendbyte(*ptr++);
  172. X
  173. X    while (*ptr) {
  174. X
  175. X            switch (readbyte(15)) {
  176. X
  177. X            case ACK: break;
  178. X
  179. X            case TIMEOUT: {
  180. X                logit("Timeout while sending MODEM7 filename\n");
  181. X                tlogit("Timeout while sending MODEM7 filename\n");
  182. X                sendbyte(BAD_NAME);
  183. X                return (-1);
  184. X            }
  185. X
  186. X            default: {
  187. X                logit("Error while sending MODEM7 filename\n");
  188. X                tlogit("Error while sending MODEM7 filename\n");
  189. X                sendbyte(BAD_NAME);
  190. X                return (-1);
  191. X            }
  192. X        }    
  193. X
  194. X        sendbyte (*ptr++);
  195. X    }
  196. X
  197. X    /* Check checksum returned by other side against my value */
  198. X    if (readbyte(16) != cksum) {
  199. X        logit("Bad checksum while sending MODEM7 filename\n");
  200. X        tlogit("Bad checksum while sending MODEM7 filename\n");
  201. X        sendbyte(BAD_NAME);
  202. X        return (-1);
  203. X    }
  204. X
  205. X    sendbyte(ACK);
  206. X    return (0);
  207. X}
  208. X
  209. X/* Convert Unix filename to 11 character CP/M file name (8 char name,
  210. X * 3 char extension, dot in between is not included).
  211. X * map ':' into '/'; Use filename to hold name.
  212. X * code stolen from D. Thompson's (IRTF) xmodem.c
  213. X */
  214. X
  215. Xchar *
  216. Xunix_cpm(string)
  217. Xchar *string;
  218. X{
  219. X    register char *iptr, *optr, temp;
  220. X    int i;
  221. X
  222. X    char *rindex();
  223. X    char *strcpy();
  224. X
  225. X    /* blank 11 character name */
  226. X    (void) strcpy (filename,"           ");
  227. X
  228. X    /* strip off any path name */
  229. X    if ((iptr = rindex(string,'/')))
  230. X        iptr++;
  231. X    else
  232. X        iptr=string;
  233. X
  234. X    /* skip leading '.'s */
  235. X    while (*iptr == '.')
  236. X        iptr++;
  237. X
  238. X    /* copy main part of name */
  239. X    optr = filename;
  240. X    i = 8;
  241. X    while ((i--) && (*iptr) && (*iptr != '.'))
  242. X        *optr++ = *iptr++;
  243. X
  244. X    /* advance to unix extension, or end of unix name */
  245. X    while ((*iptr != '.') && (*iptr))
  246. X        iptr++;
  247. X
  248. X    /* skip over the  '.' */
  249. X    while (*iptr == '.')
  250. X        iptr++;
  251. X
  252. X    /* copy extension */
  253. X    optr = &filename[8];
  254. X    i=3;
  255. X    while ((i--) && (*iptr) && (*iptr != '.'))
  256. X        *optr++ = *iptr++;
  257. X
  258. X    filename[NAMSIZ] = '\000';
  259. X
  260. X    /* Fuss with name */
  261. X    for (iptr=filename; (temp = *iptr) ;) {
  262. X        temp &= 0177;            /* strip bit 7 (parity bit) */
  263. X        if (islower(temp))
  264. X            temp &= ~040;        /* make upper case */
  265. X        if (temp == ':')
  266. X            temp ='/';        /* map ':' into '/' */
  267. X        *iptr++ = temp;
  268. X    }
  269. X
  270. X    if (DEBUG)
  271. X        fprintf (LOGFP, "DEBUG: File %s sent as %s\n", string, filename);
  272. X
  273. X    return(filename);
  274. X}
  275. END_OF_FILE
  276.   if test 4901 -ne `wc -c <'batch.c'`; then
  277.     echo shar: \"'batch.c'\" unpacked with wrong size!
  278.   fi
  279.   # end of 'batch.c'
  280. fi
  281. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'misc.c'\"
  283. else
  284.   echo shar: Extracting \"'misc.c'\" \(4396 characters\)
  285.   sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  286. X#include "xmodem.h"
  287. X
  288. X/*  Print Help Message  */
  289. Xhelp()
  290. X    {
  291. X    fprintf(stderr, "Usage:  \txmodem ");
  292. X    fprintf(stderr, "-[rb!rt!ra!sb!st!sa][options] filename\n");
  293. X    fprintf(stderr, "Major Commands --");
  294. X    fprintf(stderr, "\n\trb <-- Receive Binary");
  295. X    fprintf(stderr, "\n\trt <-- Receive Text");
  296. X    fprintf(stderr, "\n\tra <-- Receive Apple macintosh text");
  297. X    fprintf(stderr, "\n\tsb <-- Send Binary");
  298. X    fprintf(stderr, "\n\tst <-- Send Text");
  299. X    fprintf(stderr, "\n\tsa <-- Send Apple macintosh text");
  300. X    fprintf(stderr, "\nOptions --");
  301. X    fprintf(stderr, "\n\ty  <-- Use YMODEM Batch Mode on transmit");
  302. X    fprintf(stderr, "\n\tg  <-- Select YMODEM-G Mode on receive");
  303. X    fprintf(stderr, "\n\tm  <-- Use MODEM7 Batch Mode on transmit");
  304. X    fprintf(stderr, "\n\tk  <-- Use 1K packets on transmit");
  305. X    fprintf(stderr, "\n\tc  <-- Select CRC mode on receive");
  306. X    fprintf(stderr, "\n\tt  <-- Indicate a TOO BUSY Unix system");
  307. X    fprintf(stderr, "\n\td  <-- Delete xmodem.log file before starting");
  308. X    fprintf(stderr, "\n\tl  <-- (ell) Turn OFF Log File Entries");
  309. X    fprintf(stderr, "\n\tx  <-- Include copious debugging information in log file");
  310. X    fprintf(stderr, "\n\tp  <-- Use with SunOS tip ~C command");
  311. X    fprintf(stderr, "\n\tw  <-- Wait before initial handshake");
  312. X    fprintf(stderr, "\n\te  <-- Supress EOT confirmation");
  313. X    fprintf(stderr, "\n\tn  <-- Allow mid-transfer CAN-CAN aborts");
  314. X    fprintf(stderr, "\n");
  315. X    }
  316. X
  317. X/* get type of transmission requested (text or binary) */
  318. Xgettype(ichar)
  319. Xchar ichar;
  320. X    {
  321. X    if (ichar == 't' || ichar == 'T')
  322. X        return('t');
  323. X    else if (ichar == 'b' || ichar == 'B')
  324. X        return('b');
  325. X    else if (ichar == 'a' || ichar == 'A')
  326. X        return('a');
  327. X    else
  328. X        error("Invalid Send/Receive Parameter - not t or b", FALSE);
  329. X    return('\0');
  330. X    }
  331. X
  332. X/* return a string containing transmission type */
  333. Xchar *
  334. Xprtype(ichar)
  335. Xchar ichar;
  336. X    {
  337. X    if (ichar == 't' || ichar == 'T')
  338. X        return("text");
  339. X    else if (ichar == 'b' || ichar == 'B')
  340. X        return("binary");
  341. X    else if (ichar == 'a' || ichar == 'A')
  342. X        return("apple");
  343. X    else
  344. X        return("");
  345. X    }
  346. X
  347. X/* print error message and exit; if mode == TRUE, restore normal tty modes */
  348. Xerror(msg, mode)
  349. Xchar *msg;
  350. Xint mode;
  351. X    {
  352. X    if (mode)
  353. X        restoremodes(TRUE);  /* put back normal tty modes */
  354. X    fprintf(stderr, "\r\n%s\n", msg);
  355. X    if ((LOGFLAG || DEBUG) && (LOGFP != NULL))
  356. X        {   
  357. X        fprintf(LOGFP, "XMODEM Fatal Error:  %s\n", msg);
  358. X            fclose(LOGFP);
  359. X        }
  360. X    exit(-1);
  361. X    }
  362. X
  363. X
  364. X/* Construct a proper (i.e. pretty) sector count for messages */
  365. X
  366. Xchar
  367. X*sectdisp(recvsectcnt, bufsize, plus1)
  368. Xlong recvsectcnt;
  369. Xint bufsize, plus1;
  370. X    {
  371. X    static char string[20];
  372. X    if (plus1)
  373. X        recvsectcnt += (bufsize == 128) ? 1 : 8;
  374. X    if (bufsize == 128 || recvsectcnt == 0)
  375. X        sprintf (string, "%d", recvsectcnt);
  376. X    else
  377. X        sprintf (string, "%d-%d", recvsectcnt-7, recvsectcnt);
  378. X    return(string);
  379. X    }
  380. X
  381. X/* type out debugging info */
  382. Xxmdebug(str)
  383. Xchar *str;
  384. X    {
  385. X    if (DEBUG && (LOGFP != NULL))
  386. X        fprintf(LOGFP,"DEBUG: '%s'\n",str);
  387. X    }
  388. X
  389. X/* print elapsed time and rate of transfer in logfile */
  390. X
  391. Xint quant[] = { 60, 60, 24};    
  392. Xchar sep[3][10] = { "second", "minute", "hour" };
  393. X
  394. Xprtime (numsect, seconds, fileid)
  395. Xlong numsect;
  396. Xtime_t seconds;
  397. XFILE *fileid;
  398. X
  399. X{
  400. X    register int i;
  401. X    register int Seconds;
  402. X    int nums[3];
  403. X    int rate;
  404. X
  405. X    if (numsect == 0)
  406. X        return(0);
  407. X
  408. X    Seconds = (int)seconds;
  409. X    Seconds = (Seconds > 0) ? Seconds : 0;
  410. X
  411. X    rate = (Seconds != 0) ? 128 * numsect/Seconds : 0;
  412. X
  413. X    for (i=0; i<3; i++) {
  414. X        nums[i] = (Seconds % quant[i]);
  415. X        Seconds /= quant[i];
  416. X    }
  417. X
  418. X    fprintf (fileid, "%ld Sectors Transfered in ", numsect);
  419. X
  420. X    if (rate == 0)
  421. X        fprintf (fileid, "0 seconds");
  422. X    else
  423. X        while (--i >= 0)
  424. X            if (nums[i])
  425. X                fprintf (fileid, "%d %s%c ", nums[i], &sep[i][0],
  426. X                    nums[i] == 1 ? ' ' : 's');
  427. X    fprintf (fileid, "\n");
  428. X
  429. X    if (rate != 0)
  430. X        fprintf (fileid, "Transfer Rate = %d Characters per Second\n", rate);
  431. X
  432. X    return(0);
  433. X}
  434. X
  435. X/* Print elapsed time estimate */
  436. X
  437. Xprojtime (numsect, fd)
  438. Xlong numsect;
  439. XFILE *fd;
  440. X    {
  441. X    register int i;
  442. X    register int seconds;
  443. X    int nums[3];
  444. X
  445. X    if (numsect == 0)
  446. X        return (0);
  447. X
  448. X/* constant below should really be 1280; reduced to 90% to account for time lost in overhead */
  449. X
  450. X    seconds = 1422 * numsect / ttyspeed + 1;
  451. X
  452. X    for (i=0; i<3; i++) {
  453. X        nums[i] = (seconds % quant[i]);
  454. X        seconds /= quant[i];
  455. X    }
  456. X
  457. X    fprintf (fd, "Estimated transmission time ");
  458. X
  459. X    while (--i >= 0)
  460. X        if (nums[i])
  461. X            fprintf (fd, "%d %s%c ", nums[i], &sep[i][0],
  462. X                nums[i] == 1 ? ' ' : 's');
  463. X    fprintf (fd, "\n");
  464. X    return (0);
  465. X    }
  466. END_OF_FILE
  467.   if test 4396 -ne `wc -c <'misc.c'`; then
  468.     echo shar: \"'misc.c'\" unpacked with wrong size!
  469.   fi
  470.   # end of 'misc.c'
  471. fi
  472. if test -f 'xmodem.1' -a "${1}" != "-c" ; then 
  473.   echo shar: Will not clobber existing file \"'xmodem.1'\"
  474. else
  475.   echo shar: Extracting \"'xmodem.1'\" \(10889 characters\)
  476.   sed "s/^X//" >'xmodem.1' <<'END_OF_FILE'
  477. X.TH XMODEM LOCAL "November 2, 1990"
  478. X.UC 4.2
  479. X.SH NAME
  480. Xxmodem \- Christensen protocol file transfer utility \- Version 3.9, November 1990
  481. X.SH SYNOPSIS
  482. X.B xmodem
  483. X[\fBst|sb|sa|rt|rb|ra\fR][\fBygmkctdlxpwen\fR]
  484. X[file...]
  485. X.br
  486. X.SH DESCRIPTION
  487. XThe
  488. X.I xmodem
  489. Xprogram implements the Christensen (XMODEM) file transfer
  490. Xprotocol for moving files between 4.2/4.3BSD Unix systems (and successors,
  491. Xincluding Suns) and microcomputers.
  492. XThe XMODEM/CRC protocol, the MODEM7 batch protocol, the XMODEM-1K
  493. Xblock protocol, the YMODEM batch protocol and the YMODEM-G streaming protocol
  494. Xare all supported by 
  495. X.IR xmodem .
  496. XThe ZMODEM protocol is not supported.
  497. XFor details of the XMODEM/YMODEM protocols,
  498. Xsee the document edited by Chuck Forsberg titled
  499. X.I
  500. XXMODEM/YMODEM Protocol Reference.
  501. X.sp
  502. XOption Flags are case insensitive; the cluster of flags 
  503. Xmay be preceded by an optional "-"
  504. Xcharacter.
  505. X.PP
  506. X.SH PARAMETERS
  507. XExactly one of the following must be selected:
  508. X.TP
  509. X.B rb  
  510. XReceive Binary - files are placed on the Unix disk without conversion.
  511. X.I Xmodem
  512. Xwill silently destroy existing files of the same name.
  513. X.TP
  514. X.B rt  
  515. XReceive Text - files are converted from the CP/M and MS-DOS
  516. Xformat of CR-LF pairs to the Unix convention of newline 
  517. Xcharacters only between lines.  
  518. XNull bytes are ignored and bit 8 of each character is stripped (which makes 
  519. XWordstar files much more readable).
  520. XA CTRL-Z character is deemed to indicate the EOF location in the incoming
  521. Xfile.
  522. XThe resulting file
  523. Xis acceptable to the Unix editors and compilers, and is usually slightly
  524. Xsmaller than the original file.
  525. X.I Xmodem
  526. Xwill silently destroy existing files of the same name.
  527. X.TP
  528. X.B ra
  529. XReceive Apple - same as rt save CR characters in the incoming file are 
  530. Xtranslated into Unix newline characters.
  531. X.TP
  532. X.B sb  
  533. XSend Binary - files are sent without conversion as they exist on the Unix disk.
  534. X.TP
  535. X.B st  
  536. XSend Text - newline characters in the file are converted to CR-LF pairs
  537. Xin accord with the CP/M and MS-DOS conventions for text files.  The file
  538. X"grows" in this process.
  539. X.TP
  540. X.B sa  
  541. XSend Apple - same as st save newline characters are converted into CR
  542. Xcharacters in accord with Apple Macintosh conventions for text files.
  543. X.PP
  544. X.SH OPTIONS
  545. X.TP
  546. X.B y
  547. XSelect the YMODEM batch protocol for sending files; a list of files specified
  548. Xon the command line will be sent in sequence.  The YMODEM batch protocol is 
  549. Xused automatically for file reception if the sending program requests it.
  550. XIf this flag is specified for a batch receive, (\fIxmodem rty\fR, for example),
  551. Xthe transfer will never attempt to switch from CRC to checksum mode.
  552. X.TP
  553. X.B g
  554. XSelect the YMODEM-G variant of YMODEM when receiving files.  YMODEM-G is
  555. Xautomatically invoked on transmit if the receiving program requests it.
  556. XYMODEM-G is designed for "error-free" connections with proper flow control;
  557. Xthe transmitting program blasts packets to the receiver as fast as it can
  558. Xwithout waiting for acknowledgements.  Any errors cause the entire file
  559. Xtransfer to be aborted.
  560. X.TP
  561. X.B m
  562. XSelect the MODEM7 batch protocol for sending files; a list of files specified
  563. Xon the command line will be sent in sequence.  The MODEM7 batch protocol is 
  564. Xused automatically for file reception if the sending program requests it.
  565. XIf this flag is specified for a batch receive, (\fIxmodem rbm\fR, for example),
  566. Xthe transfer starts in checksum mode rather than CRC mode.  If both "m" and
  567. X"c" are specified on a receive command, the initial "file-name" negotiations
  568. Xare done using checksums while the file transfers are done using CRC-16.
  569. X.TP
  570. X.B k
  571. XSelect the XMODEM-1K file transfer mode for sending files. Use of 1K packets on
  572. Xlow-error lines increases throughput.  
  573. XHowever, over direct connections at 9600 bps to a busy host, 1K packets may
  574. Xcause data overflows generating excessive retries.
  575. X1K packets are automatically
  576. Xused for file reception if the sending program requests it.
  577. XIf this flag is specified with the YMODEM flag in a batch receive (\fIxmodem
  578. Xrbyk\fR, for example), the program will attempt to use the "KMD/IMP" convention
  579. Xto invoke 1K file transfers.
  580. X.TP
  581. X.B c   
  582. XSelect the CRC-16 error-checking protocol on receive.  CRC mode is better at catching
  583. Xtransmission errors that occur than the alternative checksum protocol.  
  584. XCRC mode is automatically selected for file
  585. Xtransmission if the receiving modem program requests it.
  586. X.TP
  587. X.B t
  588. XIndicates the Unix system is Too Busy and 
  589. X.I xmodem
  590. Xshould fall back to a simpler I/O strategy than normal.
  591. X.TP
  592. X.B d   
  593. XDelete the 
  594. X.I xmodem.log
  595. Xfile before file transfer is begun.
  596. X.TP
  597. X.B l   
  598. XDo NOT write to the log file.  If logging is selected, a file
  599. X.I xmodem.log 
  600. Xwill be created (or appended to), with entries for significant events, errors
  601. Xand retries.  This can be useful to see why things went wrong
  602. Xwhen they do.
  603. X.TP
  604. X.B x
  605. XToggle on debug mode.  If debug mode is selected, copious and possibly
  606. Xuseful debugging information will be placed in 
  607. X.IR xmodem.log .
  608. X.TP
  609. X.B p
  610. XAssume that
  611. X.I xmodem
  612. Xis being invoked through SunOS tip (via the ~C command).  Status and error
  613. Xmessages will be sent to stderr, and hence to your screen, while the transfer
  614. Xis in progress.  
  615. X.B Do
  616. X.B not
  617. Xuse this option unless you are using tip!
  618. X.TP
  619. X.B w
  620. XWait 15 seconds before initiating the startup handshake.  Useful if handshake
  621. Xcharacters are trashing things you need to type.
  622. X.TP
  623. X.B e
  624. XSuppress EOT verification.
  625. XNormally,
  626. X.I xmodem
  627. Xtries to verify an EOT character (used to signify the end of file) by
  628. XNAKing it and waiting for the EOT to be resent.  This reliability feature
  629. Xcan generate harmless error messages in some microcomputer file transfer
  630. Xprograms; other programs refuse to work at all.  To accomodate the latter
  631. Xbrain-damaged programs, use the "e" option. 
  632. X.TP
  633. X.B n
  634. XAllow CAN-CAN aborts during mid-transfer.  Normally, as a reliability feature,
  635. XCAN-CAN aborts are only allowed at the beginning of a file transfer.  If you
  636. Xdon't like this feature, use the "n" flag.
  637. X.SH "FILE NAMES"
  638. XFiles transmitted using one of the batch modes
  639. Xwill be stored on the remote machine under a CP/M-ified name (path names
  640. Xstripped, limited
  641. Xto eight characters plus a three character extension; ":" characters will
  642. Xbe turned into "/" characters; all characters will be in monocase).  
  643. XFiles received using one of the batch modes
  644. Xwill be stored under their transmitted names (except that any "/" characters
  645. Xin the file name will be converted into ":" characters, all upper-case
  646. Xcharacters will be translated into lower case and trailing dots will be
  647. Xexpunged).
  648. X.PP
  649. XWhen a batch receive is requested,
  650. X.I xmodem
  651. Xtakes a wait and see attitude and can adapt to either batch protocol or even
  652. Xa classic XMODEM transfer (note that CRC-16 mode is automatically set under
  653. Xthese circumstances unless the b flag is specified).
  654. XIf a classic, "non-batch" XMODEM file reception takes place, 
  655. Xthe received file is stored as
  656. X.IR xmodem.in .
  657. XFile names present on the command line for a batch receive are ignored.
  658. X.SH NOTES
  659. XRemember, CRC-16 error detection and YMODEM-G streaming must be invoked by
  660. Xthe
  661. X.B receiving
  662. Xprogram while 1K blocksize must be invoked by the
  663. X.B sending
  664. Xprogram.
  665. X.PP
  666. XWhile waiting for the beginning of a file transfer, 
  667. X.I xmodem
  668. Xtreats two CAN (CTRL-X) characters that are received within 3 seconds
  669. Xas a request to abort.  CAN characters will not cause an abort if received
  670. Xin the midst of a file transfer (unless the "n" option was invoked).
  671. X.PP
  672. XIf 10 or more errors are detected during the transmission or reception of any
  673. Xone packet, the transfer is aborted.
  674. X.PP
  675. XSqueezed, compressed, ZIPed or ARCed files must be transferred in binary mode, 
  676. Xeven if they contain text.
  677. X.PP
  678. XIf you use 
  679. X.I xmodem
  680. Xover a 
  681. X.I rlogin
  682. Xlink, you may have to use the form
  683. X.IR "rlogin machine -8" .
  684. X.PP
  685. XIf an unexpected error occurs before a file is completely received, the
  686. Xincomplete file is deleted.
  687. X.PP
  688. XFiles received using both binary and text mode in a YMODEM batch transfer 
  689. Xwill be truncated
  690. Xto the file size specified in the YMODEM header (extra CR characters in the
  691. Xincoming file are correctly handled).  File sizes are included in
  692. Xthe YMODEM header when sending both binary and text files.  Thus files
  693. Xtransferred via YMODEM should preserve their exact length.
  694. XFile modification times are set for received files if present in the YMODEM
  695. Xheader; they are included in the headers for transmitted files (watch for
  696. Xtimezone problems, however).
  697. X.PP
  698. XThe "KMD/IMP" record count field in the YMODEM header is both set and read.
  699. X.PP
  700. X.I xmodem
  701. Xcan be used through the SunOS 
  702. X.I tip
  703. Xprogram to transfer files.  Use
  704. X.I tip
  705. Xto establish a session on a remote computer.  Enter the file transfer
  706. Xcommand on the remote computer to send or receive files, then use the ~C
  707. Xcommand which causes
  708. X.I tip
  709. Xto request a local command string and enter the appropriate
  710. X.I xmodem
  711. Xcommand.  Use the "p" option on the local
  712. X.I xmodem
  713. Xcommand so you will see status reports on your screen.
  714. XIf the
  715. X.I xmodem
  716. Xis running on the remote machine, use the "w" option there to halt the
  717. Xinitiation of file-transfer handshaking for a bit to allow you to enter the ~C
  718. Xcommand line without interference.
  719. X.PP
  720. XThe MODEM7 batch protocol is archaic and should only be used if YMODEM batch
  721. Xprotocols are not available in your PC's communication program.  If you must
  722. Xuse MODEM7, you may have to specify the "m" option or, preferably, "cm"
  723. Xwhen receiving files with 
  724. X.IR xmodem .
  725. X.SH EXAMPLES
  726. X.PP
  727. XTo receive a text file transmitted from a micro (using CRC-16
  728. Xerror-checking) and store it under the
  729. Xname 
  730. X.IR file.name ,
  731. Xuse the command line
  732. X.RS
  733. X.B "xmodem rtc file.name"
  734. X.RE
  735. XNote that if the transmitting program on the micro uses the 1K packet
  736. Xprotocol and/or the YMODEM batch protocol,
  737. X.I xmodem
  738. Xdetects this automatically and takes appropriate action.  Further
  739. Xnote that if one of the batch protocols is used, the received file(s)
  740. Xwill be stored under their own names and the name on the command line
  741. X(if any) will be ignored.  Finally, note that CRC-16 error checking is the
  742. Xdefault.  Thus, a generic command to receive files would be
  743. X.RS
  744. X.B "xmodem rt"
  745. X.RE
  746. X.PP
  747. XTo send a set of text files to a microcomputer using 1K packets and the
  748. XYMODEM batch protocol, use the command line
  749. X.RS
  750. X.B "xmodem styk *.txt"
  751. X.RE
  752. X.SH FILES
  753. Xxmodem.log (if logging is enabled)
  754. X.SH BUGS
  755. XBatch mode could be smarter about bad file-names in the midst of a
  756. Xbatch transmit/receive.
  757. X.PP
  758. XBatch mode could allow a mixture of binary and text files.
  759. X.PP
  760. XBare Carriage Return characters (i.e., those not immediately followed by a
  761. XLine Feed character) are mishandled in a received file when using text mode.
  762. XA file with "overstruck" lines will thus come out looking funny.
  763. X.SH SEE ALSO
  764. Xkermit(1), rz(1), sz(1)
  765. X.SH AUTHOR
  766. XSteve Grandi, National Optical Astronomy Observatories (grandi@noao.edu).  
  767. XBased on
  768. X.I xmodem
  769. Xby Brian Kantor, University of California at San Diego.
  770. XThis, in turn, was based on
  771. X.I umodem
  772. Xby Lauren Weinstein, Richard Conn and others.
  773. END_OF_FILE
  774.   if test 10889 -ne `wc -c <'xmodem.1'`; then
  775.     echo shar: \"'xmodem.1'\" unpacked with wrong size!
  776.   fi
  777.   # end of 'xmodem.1'
  778. fi
  779. if test -f 'xmodem.h' -a "${1}" != "-c" ; then 
  780.   echo shar: Will not clobber existing file \"'xmodem.h'\"
  781. else
  782.   echo shar: Extracting \"'xmodem.h'\" \(3839 characters\)
  783.   sed "s/^X//" >'xmodem.h' <<'END_OF_FILE'
  784. X#include <ctype.h>
  785. X#include <stdio.h>
  786. X#include <sys/types.h>
  787. X#include <sys/stat.h>
  788. X#include <sys/time.h>
  789. X#include <sgtty.h>
  790. X#include <signal.h>
  791. X
  792. X/* define macros to print messages in log file */
  793. X#define  logit(string) if(LOGFLAG)fprintf(LOGFP,string)
  794. X#define  logitarg(string,argument) if(LOGFLAG)fprintf(LOGFP,string,argument)
  795. X#define  tlogit(string) if(TIPFLAG)fprintf(stderr,string)
  796. X#define  tlogitarg(string,argument) if(TIPFLAG)fprintf(stderr,string,argument)
  797. X
  798. X#define         VERSION    "3.9 (November 1990)"
  799. X#define      FALSE      0
  800. X#define      TRUE       1
  801. X
  802. X
  803. X/*  ASCII Constants  */
  804. X#define      SOH      001 
  805. X#define         STX    002
  806. X#define         ETX    003
  807. X#define      EOT    004
  808. X#define         ENQ    005
  809. X#define      ACK      006
  810. X#define         LF        012   /* Unix LF/NL */
  811. X#define         CR        015  
  812. X#define      NAK      025
  813. X#define         SYN    026
  814. X#define         CAN    030
  815. X#define         ESC    033
  816. X
  817. X/*  XMODEM Constants  */
  818. X#define      TIMEOUT      -1
  819. X#define      ERRORMAX      10    /* maximum errors tolerated while transferring a packet */
  820. X#define      WAITFIRST  1     /* seconds between startup characters in read */
  821. X#define      STERRORMAX    60    /* maximum "errors" tolerated in read startup */
  822. X#define      CRCSWMAX    30    /* maximum time to try CRC mode before switching */
  823. X#define      NAKMAX    120   /* maximum times to wait for initial NAK when sending */
  824. X#define      RETRYMAX      5     /* maximum retries to be made certain handshaking routines */
  825. X#define      KSWMAX    5     /* maximum errors before switching to 128 byte packets */
  826. X#define      EOTMAX    10    /* maximum times sender will send an EOT to end transfer */
  827. X#define      SLEEPNUM    100   /* target number of characters to collect during sleepy time */
  828. X#define         BBUFSIZ    1024  /* buffer size */
  829. X#define      NAMSIZ    11    /* length of a CP/M file name string */
  830. X#define         CTRLZ    032   /* CP/M EOF for text (usually!) */
  831. X#define      CRCCHR    'C'   /* CRC request character */
  832. X#define      KCHR    'K'   /* 1K block request character */
  833. X#define      GCHR    'G'   /* Ymodem-G request character */
  834. X#define      BAD_NAME    'u'   /* Bad filename indicator */
  835. X#define      TIPDELAY    15    /* seconds to delay handshake startup when -w */
  836. X
  837. X#define      CREATMODE    0644  /* mode for created files */
  838. X
  839. X/* GLOBAL VARIABLES */
  840. X
  841. Xint ttyspeed;        /* tty speed (bits per second) */
  842. Xunsigned char buff[BBUFSIZ];    /* buffer for data */
  843. Xint nbchr;        /* number of chars read so far for buffered read */
  844. Xlong filelength;    /* length specified in YMODEM header */
  845. Xlong fileread;        /* characters actually read so far in file */
  846. Xchar filename[256];    /* place to construct filenames */
  847. Xint yfilesleft;        /* # of files left for YMODEM header */
  848. Xlong ytotleft;        /* # of bytes left for YMODEM header */
  849. X
  850. XFILE *LOGFP;        /* descriptor for LOG file */
  851. X
  852. X/* option flags and state variables */
  853. Xchar    XMITTYPE;    /* text or binary? */
  854. Xint    DEBUG;        /* keep debugging info in log? */
  855. Xint    RECVFLAG;    /* receive? */
  856. Xint    SENDFLAG;    /* send? */
  857. Xint    BATCH;        /* batch? (Now used as a state variable) */
  858. Xint    CRCMODE;    /* CRC or checksums? */
  859. Xint    DELFLAG;    /* don't delete old log file? */
  860. Xint    LOGFLAG;    /* keep log? */
  861. Xint    LONGPACK;     /* do not use long packets on transmit? */
  862. Xint    MDM7BAT;    /* MODEM7 batch protocol */
  863. Xint    YMDMBAT;    /* YMODEM batch protocol */
  864. Xint    TOOBUSY;    /* turn off sleeping in packet read routine */
  865. Xint    TIPFLAG;    /* for tip ~C command */
  866. Xint    DELAYFLAG;    /* for startup delay */
  867. Xint    NOEOT;        /* suppress EOT verification */
  868. Xint    CANCAN;        /* allow CAN-CAN aborts anytime */
  869. Xint    YMODEMG;    /* YMODEM-G variant of YMODEM */
  870. X
  871. Xint    CHECKLENGTH;    /* Are we truncating a file to a YMODEM length? */
  872. X
  873. X
  874. X/*   CRC-16 constants.  From Usenet contribution by Mark G. Mendel, 
  875. X     Network Systems Corp.  (ihnp4!umn-cs!hyper!mark)
  876. X*/
  877. X
  878. X    /* the CRC polynomial. */
  879. X#define    P    0x1021
  880. X
  881. X    /* number of bits in CRC */
  882. X#define W    16
  883. X
  884. X    /* the number of bits per char */
  885. X#define B    8
  886. END_OF_FILE
  887.   if test 3839 -ne `wc -c <'xmodem.h'`; then
  888.     echo shar: \"'xmodem.h'\" unpacked with wrong size!
  889.   fi
  890.   # end of 'xmodem.h'
  891. fi
  892. echo shar: End of archive 3 \(of 3\).
  893. cp /dev/null ark3isdone
  894. MISSING=""
  895. for I in 1 2 3 ; do
  896.     if test ! -f ark${I}isdone ; then
  897.     MISSING="${MISSING} ${I}"
  898.     fi
  899. done
  900. if test "${MISSING}" = "" ; then
  901.     echo You have unpacked all 3 archives.
  902.     rm -f ark[1-9]isdone
  903. else
  904.     echo You still must unpack the following archives:
  905.     echo "        " ${MISSING}
  906. fi
  907. exit 0
  908. exit 0 # Just in case...
  909.